package service;

import java.util.List;

import dao.IAccountDAO;
import entity.Account;

public class AccountServiceImp implements IAccountService {

	private IAccountDAO accountDao;
	
	public void save(Account account) {
		accountDao.save(account);
	}

	public void update(Account account) {
		accountDao.update(account);
	}
	
	public void delete(Account account) {
		accountDao.delete(account);
	}
	
	public Account getById(int id) {
		return accountDao.getById(id);
	}
	
	public List<Account> getAll() {
		return accountDao.getAll();
	}

	public void transfer(Account source, Account dest, int amount) {
		//1、修改Account
		source.withdraw(amount);
		dest.deposit(amount);
		
		//2、把Account持久化
		try {
			accountDao.update(source);
			Integer.parseInt("jj");
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
		
		accountDao.update(dest);
	}

	public void setAccountDao(IAccountDAO accountDao) {
		this.accountDao = accountDao;
	}

}
